package com.demoo.zjsu.util.javamail;

import org.springframework.mail.SimpleMailMessage;

/**
 * Created by jshjsh on 2016/8/13.
 */
public class SimpleMailSender extends SpringMailSender{

    public static SimpleMailSender sender;

    private SimpleMailSender(Target target) {
        super.target = target;
    }

    public static SimpleMailSender getSenderInstance(Target target) {
        if (sender == null) {
            sender = new SimpleMailSender(target);
        }
        return sender;
    }
    /**
     * 调用sendSimpleMail即可
      */

    @Override
    public void initMessage() {
        initSimpleMessage();
    }

    public void initSimpleMessage(){
        simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setText(target.getText());
        simpleMailMessage.setSubject(target.getSubject());
        simpleMailMessage.setTo(Target.getSetTo());
        simpleMailMessage.setFrom(Target.getSetFrom());
    }


    /**
     * 封装完成
     * @param subject
     * @param text
     */
   public static void executeMail(String subject,String text){
       Target target = new Target(subject, text);
       SimpleMailSender sender = SimpleMailSender.getSenderInstance(target);
       sender.sendSimpleMail();
   }

}
